<template>
	<view class="box">
		<!-- banner 广告位 -->
		<view class="secondary-banner">
			<image src="../static/banner3.jpg"></image>
		</view>
		<!-- 微信打印 -->
		<view class="secondary-print flex just-between align-center" @click="chooseMessageFile(0)">
			<view class="secondary-img">
				<image src="../static/wechat1@2x.png"></image>
			</view>
			<view class="">
				<!-- 标题 -->
				<view class="secondary-title Bold">
					选择微信文档打印
				</view>
				<!-- 副标题 -->
				<view class="secondary-futitle Medium">
					从微信聊天记录中选择文档打印
				</view>
			</view>
			<!-- 图片 -->
			<view class="secondary-jt">
				<image src="../static/into@2x.png"></image>
			</view>
		</view>
		<view class="secondary-print flex just-between align-center" @click="chooseMessageFile(1)">
			<view class="" style="width: 82rpx;height: 74rpx;">
				<image src="../static/photo@2x.png"></image>
			</view>
			<view class="" style="margin-left: -154rpx;">
				<!-- 标题 -->
				<view class="secondary-title Bold">
					手机图片打印
				</view>
				<!-- 副标题 -->
				<view class="secondary-futitle Medium">
					将图片打印到A4纸上
				</view>
			</view>
			<!-- 图片 -->
			<view class="secondary-jt">
				<image src="../static/into@2x.png"></image>
			</view>
		</view>
		<!-- A4纸张打印 -->
		<!-- <web-view src="http://weixin.qq.com/q/02AWu089cudNi1e-io1xcs">二位得分</web-view> -->
		<view style="width:100%;">
			<official-account></official-account>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from "@/utils/applet/login.js"
	import {
		A4fail,
		wxfile
	} from "@/utils/applet/appletWxfail.js"
	export default {
		data() {
			return {
				openid: '',
				orderId: '', //订单号
				messageListWx: {
					path: [],
					orderId: '', //订单号 
				}
			}
		},
		onLoad(options) {
			// if (options.q) {
			// var scan_url = decodeURIComponent(options.q);
			var scan_url = "https://api.cloudmis.com?id='8'&orderId=A47B5D87FE444B00976787A781E15279"
			// var reg = /[a-z]+:\/\/([A-Za-z0-9.]+)+\?(([a-z])+=([A-Za-z0-9']+)+)+\&([A-Za-z0-9]+)+=([A-Za-z0-9']+)/i;
			var reg = /[a-z]+:\/\/([A-Za-z0-9.]+)+\?(([a-z])+=([A-Za-z0-9']+)+)+\&([A-Za-z0-9]+)+=([A-Za-z0-9']+)/i;
			var arr = scan_url.match(reg);
			console.log(arr[6], 'arr[6]')
			this.orderId = arr[6]
			this.messageListWx.orderId = arr[6];
			// this.urlq = options.q//完全的链接
			// } 
		},
		onShow() {
			this.openid = uni.getStorageSync('openid');
		},
		methods: {
			spu() {
				var text = [{
					"field": 'SPUId',
					"value": 1014,
				}];
				this.$store.commit("spuid", text)
			},
			chooseMessageFile(num) {
				if (this.openid) {
					this.spu();
					if (this.$store.state.sku) {
						if (num == 0) {
							this.file();
						};
						if (num == 1) {
							this.navto();
						}
					} else {
						uni.showLoading({
							title: '等待中...'
						})
					}

				} else {
					// 未登录
					login().then(res => {
						this.spu();
						if (this.$store.state.sku) {
							if (num == 0) {
								this.file();
							};
							if (num == 1) { //A4
								this.navto();
							}
						} else {
							uni.showLoading({
								title: '等待中...'
							})
						}
					})
				}
			},
			// a4纸打印
			navto() {
				if (this.$store.state.sku) {
					A4fail(6).then(res => {
						console.log(res, 'A4')
						if (typeof res == 'string' && res != undefined) {
							uni.hideLoading()
							this.messageListWx.path = JSON.parse(res).pathList;
							console.log(this.messageListWx, 'this.messageListWx')
							let ParseListwx = JSON.stringify(this.messageListWx)
							uni.redirectTo({
								url: './submitA4ImagePrintingApp?messageList=' + ParseListwx
							})
						}
					}).catch(erroe => {});
				}
			},
			// 文档打印
			file() {
				wxfile(1).then(res => {
					console.log(res, '1111')
					let pathlist = JSON.parse(res)
					this.messageListWx.path = pathlist.pathList;
					console.log(this.messageListWx, 'this.messageListWx')
					let ParseListwx = JSON.stringify(this.messageListWx)
					if (this.$store.state.sku) {
						uni.redirectTo({
							url: './submitDocumentPrintingApp?messageList=' + ParseListwx
						})
						console.log(ParseListwx, ' ParseListwx')
					} else {
						uni.showLoading({
							title: '等待中...'
						})
					}
				}).catch(erroe => {});
			}
		},

	}
</script>

<style>
	.u-progress-content {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.u-progress-dot {
		width: 16rpx;
		height: 16rpx;
		border-radius: 50%;
		background-color: #fb9126;
	}

	.u-progress-info {
		font-size: 28rpx;
		padding-left: 16rpx;
		letter-spacing: 2rpx;
		color: "fb9126";
		font-weight: bolder;
		color: #FFFFFF;

	}

	.secondary-print {
		height: 220rpx;
		/* padding: 40rpx 48rpx 42rpx 40rpx; */
		padding: 70rpx 40rpx 70rpx 30rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(230, 230, 230, 0.5);
		border-radius: 20rpx;
		margin-bottom: 44rpx;
		border: 2px solid #38FF38;
	}

	.secondary-title {
		font-size: 32rpx;
		color: #222222;
		margin-bottom: 24rpx;
		font-weight: bold;

	}

	.secondary-futitle {
		font-size: 28rpx;
		color: #999999;
		font-weight: 400;
	}

	.box {
		width: 100%;
		padding: 30rpx 30rpx 0rpx 30rpx
	}

	.secondary-banner {
		width: 690rpx;
		height: 350rpx;
		background: linear-gradient(107deg, #5B4FFC, #7F49F9);
		box-shadow: 0px 3px 5px 0px rgba(106, 76, 251, 0.51);
		border-radius: 10px;
		margin-bottom: 40rpx
	}

	.secondary-img {
		width: 82rpx;
		height: 74rpx;
		margin-right: -32rpx;
	}

	.secondary-jt {
		width: 20rpx;
		height: 36rpx;
	}
</style>
